<?php

namespace App\models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;


class User extends Authenticatable
{
    use EntrustUserTrait; // add this trait to your user model



    protected $table="users";


    protected $fillable = array('name','email', 'password');

    //用户注册
    public function register($data){
        $this->fill($data)->save();
        return $this;
    }

    //重置密码
    public function resetPassword($pwd,$id){
        return $this->where(array('id'=>$id))->update(array('password'=>$pwd));
    }

    //登录验证用户信息
    public function login($data){
        $res =  $this->select(['id','name','email'])->where($data)->first();
        if($res)
            return $res->toArray();
        else
            return false;
    }

    public function getUserList(){
        $res =  $this->select(['id','name','email'])->paginate(2);

        return $res;
    }

    public function getUserInfo($data){
        $res =  $this->select(['id','name','email'])->where($data)->first();
        return $res;
    }
}
